<include file="Public/min-header" />
<link href="__PUBLIC__/plugins/daterangepicker/daterangepicker-bs3.css" rel="stylesheet" type="text/css" />
<script src="__PUBLIC__/plugins/daterangepicker/moment.min.js" type="text/javascript"></script>
<script src="__PUBLIC__/plugins/daterangepicker/daterangepicker.js" type="text/javascript"></script>
<div class="wrapper">
	<style type="text/css">
		th{text-align: center;background: #eee;}
	</style>
    <include file="Public/breadcrumb"/>
	<section class="content">
       <div class="row">
       		<div class="col-xs-12">
	       		<div class="box">
	             <div class="box-header">
	             <div class="row">
  					<div class="col-md-10" style="width: 100%;">
						<div class="navbar navbar-default">
						        <form action="" id="search-form2" class="navbar-form form-inline" method="get">
									<?php
									if(session('fenbu_id')==0){
									?>
									<div class="form-group">
									 <select name="fenbu_id" id="fenbu_id" class="input-sm" style="width:120px;">
									      <option value=""> 全部</option>
										<foreach name="fenbu_list" item="v">
										   <option value="{$v['fenbu_id']}" <?php if(I('fenbu_id')==$v['fenbu_id']){ ?>selected="selected" <?php } ?>>
											{$v['fenbu_name']}
										   </option>
										</foreach>
									</select>
									</div>
									<?php
									}else{
										echo '<input type="hidden" name="fenbu_id" id="fenbu_id" value="'.session('fenbu_id').'" />';
									}
									?>
											<div class="form-group">
												<div class="input-group">
<!-- <select class="input-sm" name="driver" id="driver" style="width:150px;">
											<option value="" selected="selected">选择司机</option>
											<?php
											foreach($drivers as $v){
											?>
											<option value="{$v['company']}" <?php if(I('driver')==$v['company']){ echo 'selected'; };?>>{$v['company']}</option>
											<?php
											}
											?>
	</select> -->
													<input type="text" name="driver" placeholder="司机" id="driver"  class="input-sm form-control" style="width:150px;" value="{:I('driver')}">
												</div>
											</div>
						                                <div class="form-group">
						                                    <div class="input-group">
						                                        <input type="text" name="consignee" placeholder="商家/收货人/商铺名" id="input-member-id" class="input-sm form-control" style="width:150px;" value="{:I('consignee')}">
						                                    </div>
						                                </div>
									<div class="form-group">
										<div class="input-group">
											<input type="text" name="store" placeholder="供货商" id="store" class="input-sm form-control" style="width:150px;" value="{:I('store')}">
										</div>
									</div>
						                                <div class="form-group">
						                                    <div class="input-group">
						                                        <input type="text" name="order_sn" placeholder="订单号搜索" id="input-order-id" class="input-sm form-control" style="width:150px;" value="{:I('order_sn')}">
						                                    </div>
						                                </div>
														<div class="form-group">
															<div class="input-group">
																<input type="text" name="id" placeholder="编号搜索" id="input-id" class="input-sm form-control" style="width:150px;" value="{:I('id')}">
															</div>
														</div>
						                                <div class="form-group">
						                                    <div class="input-group" style="width: 300px;margin-left: 15px;">
						                                      <div class="input-group-addon" style="width:45%;">
						                                       		时间  <i class="fa fa-calendar"></i>
						                                      </div>
						                                      <input type="text" class="form-control" name="timegap" value="{$timegap}" id="start_time" autocomplete="off" style="width: 250px;">
						                                      </div>
						                                </div>

													<div class="form-group">
						                                    <div class="input-group" style="width: 300px;margin-left: 15px;">
						                                      <div class="input-group-addon" style="width:45%;">
						                                       		取货时间  <i class="fa fa-calendar"></i>
						                                      </div>
						                                      <input type="text" class="form-control" name="timegap2" value="" id="get_time" autocomplete="off" style="width: 250px;">
						                                      </div>
						                                </div>
						                                <div class="form-group">
						                                    <select name="status" id="status" class="input-sm" style="width:100px;"> 
																<if condition="$vo['status'] eq '0'">
																	<?php
																		if(I("status")=="0"){
																	?>
						                                        	<option value="">扣费状态</option>
						                                            <option value="0" selected="selected">未审核</option>
						                                            <option value="1">已审核</option>
						                  							<option value="2">已扣费</option>
																<?php
																}elseif(I("status")=="1"){
																?>
																	<option value="">扣费状态</option>
																	<option value="0">未审核</option>
																	<option value="1"  selected="selected">已审核</option>
																	<option value="2">已扣费</option>
																<?php
																}elseif(I("status")=="2"){
																?>
																	<option value="">扣费状态</option>
																	<option value="0">未审核</option>
																	<option value="1">已审核</option>
																	<option value="2" selected="selected">已扣费</option>
																<?php
																}else{
																?>
																<option value="">扣费状态</option>
																<option value="0">未审核</option>
																<option value="1">已审核</option>
																<option value="2">已扣费</option>
																<?php
																}
																?>
						                                    </select>
						                                </div>

									<div class="form-group">
										<select name="getorder" id="getorder" class="input-sm" style="width:100px;">
											<if condition="$vo['getorder'] eq '0'">
												<?php
																		if(I("getorder")=="0"){
																	?>
												<option value="">取货状态</option>
												<option value="0" selected="selected">未审取货</option>
												<option value="1">已取货</option>
												<option value="2">未入库</option>
												<?php
																}elseif(I("getorder")=="1"){
																?>
												<option value="">取货状态</option>
												<option value="0">未审取货</option>
												<option value="1"  selected="selected">已取货</option>
												<option value="2"  >未入库</option>
												<?php
																}elseif(I("getorder")=="2"){
																?>
												<option value="">取货状态</option>
												<option value="0">未审取货</option>
												<option value="1">已取货</option>
												<option value="2" selected="selected" >未入库</option>
												<?php
																}else{
																?>
												<option value="">取货状态</option>
												<option value="0">未审取货</option>
												<option value="1">已取货</option>
												<option value="2">未入库</option>
												<?php
																}
																?>
										</select>
									</div>

									<div class="form-group">
										<select name="print_num" id="print_num" class="input-sm" style="width:100px;">
											<if condition="$vo['print_num'] eq '0'">
												<?php
													if(I("print_num")=="0"){
																	?>
												<option value="">打印状态</option>
												<option value="0" selected="selected">未打印</option>
												<option value="1">已打印</option>
												<?php
																}elseif(I("print_num")=="1"){
																?>
												<option value="">打印状态</option>
												<option value="0">未打印</option>
												<option value="1"  selected="selected">已打印</option>
												<?php
																}else{
																?>
												<option value="">打印状态</option>
												<option value="0">未打印</option>
												<option value="1">已打印</option>
												<?php
																}
																?>
										</select>
									</div>

														<?php
														if($pda_open==1){
														?>
						                                <div class="form-group">
						                                	<a href="/index.php?m=admin&c=Order&a=tuihuo_edit_order" class="btn btn-primary margin"><i class="fa fa-search"></i>添加退货单</a>
						                                </div>
														<?php
														}else{
															echo '<span style="color:red">暂停添加,对账中..</span>';
														}
														?>

												<div class="form-group">
													<input type="hidden" name="p" value="0">
													<input class="btn btn-primary margin" type="submit" value="确定">
												</div>
													<button type="button" class="btn btn-default pull-right" id="daochu"><i class="fa fa-file-excel-o"></i>&nbsp;导出excel</button>
						                            </form>
						                    </div>
                 	</div>
		  		 </div>
	             </div><!-- /.box-header -->
	             <div class="box-body" style="margin-top: -30px;">
					 <div class="row">
						 <div class="col-sm-6 text-left">
							 全选
							 <input type="checkbox" onclick="$('input[name=\'ids\[\]\']').prop('checked', this.checked);">
							<?php
							   	if(session('role_id')==1 || session('role_id')==12 || session('role_id')==191){
							   ?>
							 <button id="act_button" type="button" onclick="act_submit('yes');" class="btn btn-primary" style="margin-left:15px;"><i class="fa"></i> 批量审核</button>
							 <?php
							   }
							   ?>
							   	<?php
							   	if(session('role_id')==1 || session('role_id')==215 || session('role_id')==13){
							   ?>
							 <button id="act_button" type="button" onclick="act_submit('quhuo');" class="btn btn-primary" style="margin-left:15px;"><i class="fa"></i> 批量取货</button>
							 <button id="act_button" type="button" onclick="act_submit('ruku');" class="btn btn-primary" style="margin-left:15px;"><i class="fa"></i> 批量入库</button>
							  <?php
							   }
							   ?>
							 <button id="act_button2" type="button" onclick="act_submit2();" class="btn btn-primary" style="margin-left:15px;"><i class="fa"></i> 批量打印</button>
<!--							 <button id="act_button2" type="button" onclick="act_submit3();" class="btn btn-primary" style="margin-left:15px;"><i class="fa"></i> 批量打印(自动合并)</button>-->
						 </div>
					 </div>
	           	 <div class="row">
	            	<div class="col-sm-12">
		              <table id="list-table" class="table table-bordered table-striped dataTable" role="grid" aria-describedby="example1_info">
		                 <thead>
		                   <tr role="row">
							   <th class="sorting text-center">选择</th>
							   <th class="sorting" align="center">编号</th>
							   <th class="sorting" align="center">分部</th>
                               <th class="sorting" align="center">单号</th>
                               <th class="sorting" align="center">备注</th>
                               <th class="sorting" align="center">司机</th>
							   <th class="sorting" align="center">商家</th>
			                   <th class="sorting" align="center">名称</th>
							   <th class="sorting" align="center">买家</th>
							   <th class="sorting" align="center">单价</th>
							   <th class="sorting" align="center">数量</th>
							   <th class="sorting" align="center">订单价</th>
							   <?php
							   	if(session('role_id')==10 ||  session('role_id')==8){}else{
							   ?>
			                   <th class="sorting" align="center">平台扣点</th>
							   <th class="sorting" align="center">应扣金额</th>
							   <th class="sorting" align="center">打印次数</th>
							   <th class="sorting" align="center">是否取货</th>
							   <?php
							   }
							   ?>
<!--							   <th class="sorting" align="center">退货时间</th>-->
							   <th class="sorting" align="center">创建时间</th>
							   <th class="sorting" align="center">审核时间</th>
							   <th class="sorting" align="center">状态</th>
							   <th class="sorting" align="center">取货时间</th>
							   <th class="sorting" align="center">退货入库状态</th>
							   <th class="sorting" align="center">申请类型</th>
							   <th class="sorting" align="center">支付状态</th>
							   <th class="sorting" align="center">操作</th>
		                   </tr>
		                 </thead>
						<tbody>
							
                         <foreach name="orderList" item="vo" key="k" >
							 <?php
							 $dsprice=(float)$vo['member_goods_price']*(float)$vo['goods_num']; //订单价
							 $ptprice=($dsprice-$vo['yijia'])*($vo['points']/100); //平台价
							 $ptprices=$dsprice-$ptprice;
							 ?>
                          <tr role="row" align="center">
							  <td class="text-center" id="biaozhus" rel="{$vo.id}">
								  <input type="checkbox" name="ids[]" title="批量审核" value="{$vo.id}">
							  </td>
							 <td>{$vo.id}</td>
							 <td>{$vo.fenbu_name}</td>
                             <td><a href="javascript:" id="chakan" rel="{$vo.order_id}">{$vo.order_sn}</a></td>
                             <td>{$vo.remark}</td>
							  <if condition="$vo[nick_name]">
								  <td>{$vo.nick_name}</td>
								  <else/>
								  <td>没找到司机</td>
							  </if>
							 <td>{$vo.store_name}</td>
                             <td>{$vo.goods_name}（{$vo.key_name}）</td>
							  <td>{$vo.company}</td>
							  <td>{$vo.member_goods_price}</td>
							 <td>{$vo.goods_num}</td>
		                     <td style="color:green;">{$dsprice}</td>
							 <?php
							 	if(session('role_id')==10  || session('role_id')==8){}else{
							 ?>
		                     <td style="color: #f39c12;">{:sanwei($ptprice)}</td>
		                     <td style="color:red;">{:sanwei($ptprices)}</td>
							 <?php
							 }
							 ?>
<!--							 <td style="color: royalblue;">{$vo.tuihuo_time|date='Y-m-d',###}</td>-->
							 <td>{$vo.print_num}次</td>

							 <td>
								 <if condition="$vo.getorder eq 2">
									 未入库
									 <else/>
									 <img width="20" height="20" src="__PUBLIC__/images/<if condition='$vo[getorder] eq 1'>yes.png<else />cancel.png</if>" onclick="changeTableVal('return_goods','id','{$vo.id}','getorder',this)"/>
								 </if>

								 </td>
		                     <td>{$vo.addtime|date='Y-m-d H:i',###}</td>
		                   	<if condition="$vo['status'] neq '0' && $vo['check_time']">
								<td>{:date('Y-m-d',strtotime($vo['check_time']))}</td>
								<else/>
								<td> </td>
							</if>
							 <td><if condition="$vo['status'] eq '2'">
							 <span style="color: green">已扣费</span> 
							 <elseif condition="$vo['status'] eq '1'" />
								 <span style="color:#f39c12">已审核</span>
								 <else/>
							 <span style="color: red">未审核</span>
							 </if></td>
							  <td>{$vo.getorder_time}</td>
							  <td>{$vo.ruku_time}</td>
							  <if condition="$vo[is_app]">
								  <td>手机申请</td>
								  <else/>
								  <td>电脑申请</td>
							  </if>
							  <td>
								  <if condition="$vo['pay_no'] != '' && $vo['pay_status'] eq '0'">
									  <span style="color:#0000ff;">未提交银行</span>
									  <elseif condition="$vo['pay_no'] != '' && $vo['pay_status'] eq '1'" />
									  <span style="color: red">银行处理中</span>
									  <elseif condition="$vo['pay_no'] != '' && $vo['pay_status'] eq '2'" />
									  <span style="color: green">银行已退款</span>
									  <else />
									  <span>线下订单</span>
								  </if>
							  </td>
							 <td><a href="/index.php?m=admin&c=Order&a=tuihuo_edit_order&id={$vo.id}" data-toggle="tooltip" title="" class="btn btn-info" data-original-title="查看详情"><i class="fa fa-eye">查看</i></a>
							 <?php
							 	if($vo['status']!='2' && $vo['pay_status'] != 2){
							 ?>
								 <?php
							 	if($vo['pay_no']!='' && $vo['order_pay_status'] == 1){
							 ?>
								 <a href="JavaScript:;" id="return_play" rel="{$vo.id}" rev="{$vo.order_id}" data-toggle="tooltip" title="" class="btn btn-warning" data-original-title="提交退款"><i class="fa fa-dashboard">提交退款</i></a>
								 <?php
							 }
							 ?>
							 <?php
							   	if(session('role_id')==1 || session('role_id')==12 || session('role_id')==191 || session('role_id')==13){
							   ?>
							 <!--<a href="JavaScript:;" id="return_del" rel="{$vo.id}" rev="{$vo.order_id}" data-toggle="tooltip" title="" class="btn btn-danger" data-original-title="删除"><i class="fa fa-trash-o"></i></a>-->
							 <?php
							 }
							 ?>
							 <?php
							 }
							 ?>
							 </td>
		                   </tr>
		                  </foreach>
						  <tr>
							  <td colspan="11" style="font-weight: bold;text-align: right;">合计：</td>
							  <td style="text-align: center;color: red;font-size: 16px;">{$heji_price}</td>
							  <td style="text-align: center;color: red;font-size: 16px;">{$heji_ptprice}</td>
							  <td style="text-align: center;color: red;font-size: 16px;">{$heji_ptprices}</td>
						  </tr>
		                   </tbody>
		                 <tfoot>
		                 </tfoot>
		               </table>
	               </div>
	          </div>
              <div class="row">
                    <div class="col-sm-6 text-right">{$page}</div>		
              </div>
	          </div>
	        </div>
       	</div>
       </div>
   </section>
</div>
<script type="text/javascript">
$(document).ready(function() {
	$('#start_time').daterangepicker({
			format:"YYYY-MM-DD HH:mm",
			singleDatePicker: false,
			showDropdowns: true,
			minDate:'2021-01-01 00:00',
			maxDate:'2030-01-01 00:00',
			startDate:'{:date("Y-m-d")} 00:00',
	        showWeekNumbers: true,
	        timePicker: true,
	        timePickerIncrement: 1,
	        timePicker12Hour: false,
	        opens: 'right',
	        buttonClasses: ['btn btn-default'],
	        applyClass: 'btn-small btn-primary',
	        cancelClass: 'btn-small',
		    locale : {
	            applyLabel : '确定',
	            cancelLabel : '取消',
	            fromLabel : '起始时间',
	            toLabel : '结束时间',
	            customRangeLabel : '自定义',
	            daysOfWeek : [ '日', '一', '二', '三', '四', '五', '六' ],
	            monthNames : [ '一月', '二月', '三月', '四月', '五月', '六月','七月', '八月', '九月', '十月', '十一月', '十二月' ],
	            firstDay : 1
	        }
	});
	$('#get_time').daterangepicker({
			format:"YYYY-MM-DD HH:mm",
			singleDatePicker: false,
			showDropdowns: true,
			minDate:'2021-01-01 00:00',
			maxDate:'2030-01-01 00:00',
			startDate:'{:date("Y-m-d")} 00:00',
	        showWeekNumbers: true,
	        timePicker: true,
	        timePickerIncrement: 1,
	        timePicker12Hour: false,
	        opens: 'right',
	        buttonClasses: ['btn btn-default'],
	        applyClass: 'btn-small btn-primary',
	        cancelClass: 'btn-small',
		    locale : {
	            applyLabel : '确定',
	            cancelLabel : '取消',
	            fromLabel : '起始时间',
	            toLabel : '结束时间',
	            customRangeLabel : '自定义',
	            daysOfWeek : [ '日', '一', '二', '三', '四', '五', '六' ],
	            monthNames : [ '一月', '二月', '三月', '四月', '五月', '六月','七月', '八月', '九月', '十月', '十一月', '十二月' ],
	            firstDay : 1
	        }
	});
	$("#list-table #chakan").click(function(){
			var myrel=$(this).attr('rel');
			var myrul='/index.php/Admin/order/detail/order_id/'+myrel;//+myrel;
				layer.open({
				  type: 2,
				  title:'订单信息',
				  shadeClose: true, //点击遮罩关闭
				  skin: 'layui-layer-rim', //加上边框
				  area: ['920px', '620px'], //宽高
				  content: myrul
			})
	    });
	$("#list-table #return_del").click(function(){
		var id=$(this).attr('rel');
		var order_id=$(this).attr('rev');
		layer.confirm('您确定要删除这个退货单吗？', {
		  btn: ['确定','取消'] //按钮
		}, function(){
		  $.post("/index.php/Admin/order/return_del",
		  {
		    id:id,
		    order_id:order_id
		  },
		  function(data,status){
			  data=JSON.parse(data);
			  if(data.code=='200'){
				  layer.msg(data.msg, {icon:6});
				  location.reload();
			  }
		  });
		});
	})


	$("#list-table #return_play").click(function(){
		var id=$(this).attr('rel');
		var order_id=$(this).attr('rev');
		layer.confirm('您确定提交银行申请退款吗？', {
			btn: ['确定','取消'] //按钮
		}, function(){
			$.post("/index.php/Admin/order/return_play",
					{
						id:id,
						order_id:order_id
					},
					function(data,status){
						data=JSON.parse(data);
						if(data.code=='200'){
							layer.msg(data.msg, {icon:6});
							location.reload();
						}else{
							layer.msg(data.msg, {icon:5});
							location.reload();
						}
					});
		});
	})

	$("#daochu").click(function(){
		var consignee=$("#input-member-id").val();
		var order_sn=$("#input-order-id").val();
		var add_time=$("#start_time").val();
		var get_time=$("#get_time").val();
		var fenbu_id=$("#fenbu_id").val();
		var status=$("#status").val();
		var driver=$("#driver").val();
		var getorder=$("#getorder").val();
		var store=$("#store").val();
		var print_num=$("#print_num").val();
		location.href="/index.php/Admin/order/export_tuihuo?order_sn="+order_sn+"&consignee="+consignee+"&add_time="+add_time+"&status="+status+"&fenbu_id="+fenbu_id+"&driver="+driver+"&getorder="+getorder+"&store="+store+"&print_num="+print_num+"&get_time="+get_time+"&action=daochu";
	})
});



function get_select_id_str() {
	if ($('input[name="ids\[\]"]:checked').length == 0)
		return false;
	var goods_arr = Array();
	$('input[name="ids\[\]"]:checked').each(function () {
		goods_arr.push($(this).val());
	});
	var id_str = goods_arr.join(',');
	return id_str
}

//批量操作提交
function act_submit(action) {
	//prompt层
	var ids = get_select_id_str();
	if (ids == false) {
		layer.alert('请勾选要操作的退货订单', {icon: 2});
		return;
	}
	console.log(ids);
	if(action == 'yes'){
		layer.confirm('确定审核吗？', {
			btn: ['确定','取消'] //按钮
		}, function(){
			layer.prompt({
				formType: 2,
				title: '输入审核时间',
				value:'{$check_time}'
			}, function(value, index, elem){
				$.post('/index.php/Admin/Order/tuihuo_list',{action:action,datas:ids,check_time:value},function(res){
					if(res!=''){
						layer.msg('操作成功！', {icon:6},function(){
							window.location.reload();
						});
					}else{
						layer.msg('操作！', {icon:5});
					}
				});
			})


		});
	}else{
		layer.confirm('确定操作吗？', {
			btn: ['确定','取消'] //按钮
		}, function(){
			$.post('/index.php/Admin/Order/tuihuo_list',{action:action,datas:ids},function(res){
				if(res!=''){
					layer.msg('操作成功！', {icon:6},function(){
						window.location.reload();
					});
				}else{
					layer.msg('操作！', {icon:5});
				}
			});
		});
	}

}

//批量操作提交
function act_submit2() {
	//prompt层
	var ids = get_select_id_str();
	if (ids == false) {
		layer.alert('请勾选要操作的退货订单', {icon: 2});
		return;
	}
	window.open('/index.php/Admin/Order/return_print/ids/'+ids);
}

function act_submit3() {
	//prompt层
	var ids = get_select_id_str();
	if (ids == false) {
		layer.alert('请勾选要操作的退货订单', {icon: 2});
		return;
	}
	window.open('/index.php/Admin/Order/return_print2/ids/'+ids);
}
</script>
</body>
</html>